//
//  NSDateFormatter+Format.m
//  FindAJob_oc
//
//  Created by zhengbing on 6/27/16.
//  Copyright © 2016 zhengbing. All rights reserved.
//

#import "NSDateFormatter+Format.h"

@implementation NSDateFormatter (Format)
+ (NSDate *)dateWithString:(NSString *)dateString
{
    NSDateFormatter *format = [[NSDateFormatter alloc]init];
    [format setDateFormat:@"YYYY-MM-dd"];
    return [format dateFromString:dateString];
}

+ (NSString *)stringWithDate:(NSDate *)date
{
    NSDateFormatter *format = [[self alloc]init];
    [format setDateFormat:@"YYYY-MM-dd"];
    return [format stringFromDate:date];
}

+ (NSDate *)dateTimeWithString:(NSString *)dateString
{
    NSDateFormatter *format = [[self alloc]init];
    [format setDateFormat:@"YYYY-MM-dd HH:mm:ss"];
    return [format dateFromString:dateString];
}

+ (NSDate *)dateHourAndMintueWithString:(NSString *)dateString
{
    NSDateFormatter *format = [[self alloc]init];
    [format setDateFormat:@"YYYY-MM-dd HH:mm"];
    return [format dateFromString:dateString];
}
+ (NSString *)stringTimeWithDate:(NSDate *)date
{
    NSDateFormatter *format = [[self alloc]init];
    [format setDateFormat:@"YYYY-MM-dd HH:mm:ss"];
    return [format stringFromDate:date];
}

+ (NSString *)localStringWithDate:(NSDate *)date
{
    NSDateFormatter *format = [[self alloc]init];
    [format setDateFormat:@"YYYY年MM月dd日"];
    return [format stringFromDate:date];
}

+ (NSString *)localStringAndTimeWithDate:(NSDate *)date
{
    NSDateFormatter *format = [[self alloc]init];
    [format setDateFormat:@"YYYY年MM月dd日 HH:mm:ss"];
    return [format stringFromDate:date];
}

+ (NSString *)localStringOnlyMonthAndDayWithDate:(NSDate *)date
{
    NSDateFormatter *format = [[self alloc]init];
    [format setDateFormat:@"MM月dd日"];
    return [format stringFromDate:date];
}

+ (NSString *)localStringOnlyHourAndMintusWithDate:(NSDate *)date
{
    NSDateFormatter *format = [[self alloc]init];
    [format setDateFormat:@"HH:mm"];
    return [format stringFromDate:date];
}

+ (NSString *)localStringOnlyYearAndMonthWithDate:(NSDate *)date
{
    NSDateFormatter *format = [[self alloc]init];
    [format setDateFormat:@"YYYY年MM月"];
    return [format stringFromDate:date];
}
+ (NSString *)stringMonthAndHourAndMintueWithDate:(NSString *)dateString{
    NSDateFormatter *format = [self new];
    [format setDateFormat: @"yyyy-MM-dd HH:mm:ss"];
    NSDate * theDate = [format dateFromString:dateString];
    [format setDateFormat: @"MM月dd日 HH:mm"];
    return [format stringFromDate:theDate];
}


+ (NSString *)formatterDateStringWithDateString:(NSString *)dateString{
    NSDateFormatter *format = [self new];
    [format setDateFormat: @"yyyy-MM-dd HH:mm:ss"];
    NSDate * theDate = [format dateFromString:dateString];
    [format setDateFormat: @"yyyy.MM.dd HH:mm"];
    return [format stringFromDate:theDate];
}


+ (NSString *)formatterDateStringIncludeLineWithDateString:(NSString *)dateString{
    NSDateFormatter *format = [self new];
    [format setDateFormat: @"yyyy-MM-dd HH:mm:ss"];
    NSDate * theDate = [format dateFromString:dateString];
    [format setDateFormat: @"yyyy-MM-dd HH:mm"];
    return [format stringFromDate:theDate];
}

+ (NSString *)formatterDateStringWithoutHourAndMinWithDateString:(NSString *)dateString{
    NSDateFormatter *format = [self new];
    [format setDateFormat: @"yyyy-MM-dd HH:mm:ss"];
    NSDate * theDate = [format dateFromString:dateString];
    [format setDateFormat: @"yyyy.MM.dd"];
    return [format stringFromDate:theDate];
}


+ (NSString *)ybFormatterDateStringWithoutHourAndMinWithDateString:(NSString *)dateString{
    NSDateFormatter *format = [self new];
    [format setDateFormat: @"yyyy-MM-dd HH:mm"];
    NSDate * theDate = [format dateFromString:dateString];
    [format setDateFormat: @"yyyy.MM.dd"];
    return [format stringFromDate:theDate];
}
@end
